package IC.Semantics.symbols;

import java.util.HashMap;

/**
 * this class describes the global symbol table 
 */
public class GlobalSymbolTable extends SymbolTable
{
	public GlobalSymbolTable(String ICFilePath) {
		super(null, ICFilePath);
	}
	
	public ClassSymbol lookup(String name){
		return (ClassSymbol) entries.get(name);
	}
	

	@Override
	public String dump()
	{
		// print all entries in its symbol-table (will have only classes)
		StringBuilder global_symtab_str = new StringBuilder("Global Symbol Table: "+this.getName());
		for (SemanticSymbol class_symbol: entries.values()) {
			global_symtab_str.append("\n\tClass: "+class_symbol.getName());
        }
        
        // print list of children tables
        if (!children.isEmpty()) {
        	global_symtab_str.append("\nChildren tables: ");
            for (String class_symtab_name: children.keySet())
            	global_symtab_str.append(class_symtab_name+", ");
            // not printing last comma
            global_symtab_str.delete(global_symtab_str.length()-2, global_symtab_str.length());
        }
        global_symtab_str.append("\n\n");
        
        // recursively print class symbol tables, their children, etc..
        for (SymbolTable class_symtab: children.values()){
        	global_symtab_str.append(class_symtab.dump()); // Overridden in ClassSymbolTable
        }
        
        return global_symtab_str.toString();
	}

	
	// each class name is mapped to his class table symbol table (i.e hierarchy leaf)
	public static HashMap<String, ClassSymbolTable> classHier = new HashMap<String, ClassSymbolTable>();
	
	public static String mainClassName;
	
}
